define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree', 'cookie'], function ($, undefined, Backend, Table, Form, undefined, undefined) {

    //读取选中的条目
    $.jstree.core.prototype.get_all_checked = function (full) {
        var obj = this.get_selected(), i, j;
        for (i = 0, j = obj.length; i < j; i++) {
            obj = obj.concat(this.get_node(obj[i]).parents);
        }
        obj = $.grep(obj, function (v, i, a) {
            return v != '#';
        });
        obj = obj.filter(function (itm, i, a) {
            return i == a.indexOf(itm);
        });
        return full ? $.map(obj, $.proxy(function (i) {
            return this.get_node(i);
        }, this)) : obj;
    };
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'agent/index' + location.search,
                    add_url: 'agent/add2',
                    edit_url: 'agent/edit2',
                    del_url: 'agent/del',
                    multi_url: 'agent/multi',
                    import_url: 'agent/import',
                    table: 'agent',
                }
            });

            var table = $("#table");

            //$(".btn-add").data("area", ["100%", "100%"]);

            //var url = 'dd/user/edfp/ids/' + this.newdduser_id;
            //var options = {
            //    shadeClose: false,
            //    shade: [0.3, '#393D49'],
            //    area: ["80%", "80%"],
            //    callback: function (data) {
            //        console.log(data);
            //        parent.Layer.close(index);
            //    }
            //};
            //Fast.api.open(url, "继续分配额度", options);

            var buttons = [];
            buttons.push({
                name: 'op1',
                title: __('分配额度'),
                text: __('分配额度'),
                classname: 'btn btn-xs btn-info btn-dialog',
                url: 'dd/user/edfp/'
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                //pagination: false,
                search: false,
                commonSearch: false,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        {field: 'admin.username', title: __('Admin_id')},
                        //{field: 'pid', title: __('Parent_id')},
                        {field: 'user.nickname', title: __('Dd_user_id'), operate: false},
                        {field: 'level', title: __('Level'), operate: false},
                        //{field: 'dd_user_id', title: __('Dd_user_id'), operate: false},
                        {field: 'game1_proportion', title: __('Game1_proportion'), operate: false},
                        {field: 'game1_refund', title: __('Game1_refund'), operate: false},
                        {field: 'game2_proportion', title: __('Game2_proportion'), operate: false},
                        {field: 'game2_refund', title: __('Game2_refund'), operate: false},
                        {field: 'handicap', title: __('Handicap'), operate: false},
                        //{field: 'new_game1_proportion', title: __('New_game1_proportion'), operate: false},
                        //{field: 'new_game1_refund', title: __('New_game1_refund'), operate: false},
                        //{field: 'new_game2_proportion', title: __('New_game2_proportion'), operate: false},
                        //{field: 'new_game2_refund', title: __('New_game2_refund'), operate: false},
                        //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.id', title: __('User.id')},
                        //{field: 'user.login_name', title: __('User.login_name'), operate: 'LIKE'},
                        //{field: 'user.login_pass', title: __('User.login_pass'), operate: 'LIKE'},
                        //{field: 'user.openid', title: __('User.openid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openidb', title: __('User.openidb'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openida', title: __('User.openida'), operate: 'LIKE'},
                        //{field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        //{field: 'user.headimg', title: __('User.headimg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        //{field: 'user.sub_time', title: __('User.sub_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.subscribe', title: __('User.subscribe')},
                        //{field: 'user.parent1', title: __('User.parent1')},
                        //{field: 'user.parent2', title: __('User.parent2')},
                        //{field: 'user.parent3', title: __('User.parent3')},
                        //{field: 'user.agent1', title: __('User.agent1')},
                        //{field: 'user.agent2', title: __('User.agent2')},
                        //{field: 'user.agent3', title: __('User.agent3')},
                        //{field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        //{field: 'user.num', title: __('User.num')},
                        //{field: 'user.yingkui', title: __('User.yingkui'), operate:'BETWEEN'},
                        //{field: 'user.points', title: __('User.points'), operate:'BETWEEN'},
                        //{field: 'user.expense', title: __('User.expense'), operate:'BETWEEN'},
                        //{field: 'user.withdraw', title: __('User.withdraw'), operate:'BETWEEN'},
                        //{field: 'user.parent4', title: __('User.parent4')},
                        //{field: 'user.parent5', title: __('User.parent5')},
                        //{field: 'user.parent6', title: __('User.parent6')},
                        //{field: 'user.parent7', title: __('User.parent7')},
                        //{field: 'user.parent8', title: __('User.parent8')},
                        //{field: 'user.parent20', title: __('User.parent20')},
                        //{field: 'user.parent19', title: __('User.parent19')},
                        //{field: 'user.parent18', title: __('User.parent18')},
                        //{field: 'user.parent17', title: __('User.parent17')},
                        //{field: 'user.parent16', title: __('User.parent16')},
                        //{field: 'user.parent15', title: __('User.parent15')},
                        //{field: 'user.parent14', title: __('User.parent14')},
                        //{field: 'user.parent13', title: __('User.parent13')},
                        //{field: 'user.parent12', title: __('User.parent12')},
                        //{field: 'user.parent11', title: __('User.parent11')},
                        //{field: 'user.parent10', title: __('User.parent10')},
                        //{field: 'user.parent9', title: __('User.parent9')},
                        //{field: 'user.is_tong', title: __('User.is_tong')},
                        //{field: 'user.type', title: __('User.type')},
                        //{field: 'user.yong', title: __('User.yong'), operate:'BETWEEN'},
                        //{field: 'user.yongtime', title: __('User.yongtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.zhifubao', title: __('User.zhifubao'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.xingming', title: __('User.xingming'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.cashimg', title: __('User.cashimg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.lahei', title: __('User.lahei')},
                        //{field: 'user.zbbz', title: __('User.zbbz'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.ip', title: __('User.ip'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openidtx', title: __('User.openidtx'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.handicap', title: __('User.handicap'), operate: 'LIKE'},
                        //{field: 'user.parent_id', title: __('User.parent_id')},
                        //{field: 'user.game1_refund', title: __('User.game1_refund'), operate: 'LIKE'},
                        //{field: 'user.game2_refund', title: __('User.game2_refund'), operate: 'LIKE'},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            //buttons: buttons,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index2: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'agent/index2' + location.search,
                    add_url: 'agent/add2',
                    edit_url: 'agent/edit2',
                    del_url: 'agent/del',
                    multi_url: 'agent/multi',
                    import_url: 'agent/import',
                    table: 'agent',
                }
            });

            var table = $("#table");

            var buttons = [];
            buttons.push({
                name: 'op1',
                title: __('分配额度'),
                text: __('分配额度'),
                classname: 'btn btn-xs btn-info btn-dialog',
                url: 'dd/user/edfp/'
            });
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                //pk: 'id',
                //sortName: 'id',
                //fixedColumns: true,
                //fixedRightNumber: 1,
                pagination: false,
                search: false,
                commonSearch: false,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'admin_id', title: __('Admin_id')},
                        {field: 'pid', title: __('Parent_id')},
                        {
                            field: 'name', title: __('Name'), align: 'left', formatter: function (value, row, index) {
                            return value.toString().replace(/(&|&amp;)nbsp;/g, '&nbsp;');
                        }
                        },
                        {field: 'level', title: __('Level'), operate: false},
                        {field: 'dd_user_id', title: __('Dd_user_id'), operate: false},
                        {field: 'game1_proportion', title: __('Game1_proportion'), operate: false},
                        {field: 'game1_refund', title: __('Game1_refund'), operate: false},
                        {field: 'game2_proportion', title: __('Game2_proportion'), operate: false},
                        {field: 'game2_refund', title: __('Game2_refund'), operate: false},
                        {field: 'handicap', title: __('Handicap'), operate: false},
                        {field: 'new_game1_proportion', title: __('New_game1_proportion'), operate: false},
                        {field: 'new_game1_refund', title: __('New_game1_refund'), operate: false},
                        {field: 'new_game2_proportion', title: __('New_game2_proportion'), operate: false},
                        {field: 'new_game2_refund', title: __('New_game2_refund'), operate: false},
                        //{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.id', title: __('User.id')},
                        //{field: 'user.login_name', title: __('User.login_name'), operate: 'LIKE'},
                        //{field: 'user.login_pass', title: __('User.login_pass'), operate: 'LIKE'},
                        //{field: 'user.openid', title: __('User.openid'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openidb', title: __('User.openidb'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openida', title: __('User.openida'), operate: 'LIKE'},
                        //{field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        //{field: 'user.headimg', title: __('User.headimg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        //{field: 'user.sub_time', title: __('User.sub_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.subscribe', title: __('User.subscribe')},
                        //{field: 'user.parent1', title: __('User.parent1')},
                        //{field: 'user.parent2', title: __('User.parent2')},
                        //{field: 'user.parent3', title: __('User.parent3')},
                        //{field: 'user.agent1', title: __('User.agent1')},
                        //{field: 'user.agent2', title: __('User.agent2')},
                        //{field: 'user.agent3', title: __('User.agent3')},
                        //{field: 'user.money', title: __('User.money'), operate:'BETWEEN'},
                        //{field: 'user.num', title: __('User.num')},
                        //{field: 'user.yingkui', title: __('User.yingkui'), operate:'BETWEEN'},
                        //{field: 'user.points', title: __('User.points'), operate:'BETWEEN'},
                        //{field: 'user.expense', title: __('User.expense'), operate:'BETWEEN'},
                        //{field: 'user.withdraw', title: __('User.withdraw'), operate:'BETWEEN'},
                        //{field: 'user.parent4', title: __('User.parent4')},
                        //{field: 'user.parent5', title: __('User.parent5')},
                        //{field: 'user.parent6', title: __('User.parent6')},
                        //{field: 'user.parent7', title: __('User.parent7')},
                        //{field: 'user.parent8', title: __('User.parent8')},
                        //{field: 'user.parent20', title: __('User.parent20')},
                        //{field: 'user.parent19', title: __('User.parent19')},
                        //{field: 'user.parent18', title: __('User.parent18')},
                        //{field: 'user.parent17', title: __('User.parent17')},
                        //{field: 'user.parent16', title: __('User.parent16')},
                        //{field: 'user.parent15', title: __('User.parent15')},
                        //{field: 'user.parent14', title: __('User.parent14')},
                        //{field: 'user.parent13', title: __('User.parent13')},
                        //{field: 'user.parent12', title: __('User.parent12')},
                        //{field: 'user.parent11', title: __('User.parent11')},
                        //{field: 'user.parent10', title: __('User.parent10')},
                        //{field: 'user.parent9', title: __('User.parent9')},
                        //{field: 'user.is_tong', title: __('User.is_tong')},
                        //{field: 'user.type', title: __('User.type')},
                        //{field: 'user.yong', title: __('User.yong'), operate:'BETWEEN'},
                        //{field: 'user.yongtime', title: __('User.yongtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'user.zhifubao', title: __('User.zhifubao'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.xingming', title: __('User.xingming'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.cashimg', title: __('User.cashimg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.lahei', title: __('User.lahei')},
                        //{field: 'user.zbbz', title: __('User.zbbz'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.ip', title: __('User.ip'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.openidtx', title: __('User.openidtx'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        //{field: 'user.handicap', title: __('User.handicap'), operate: 'LIKE'},
                        //{field: 'user.parent_id', title: __('User.parent_id')},
                        //{field: 'user.game1_refund', title: __('User.game1_refund'), operate: 'LIKE'},
                        //{field: 'user.game2_refund', title: __('User.game2_refund'), operate: 'LIKE'},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: function (value, row, index) {
                                if (Config.admin.group_ids.indexOf(parseInt(row.id)) > -1) {
                                    return '';
                                }
                                return Table.api.formatter.operate.call(this, value, row, index);
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        add2: function () {
            new Vue({
                el: '#configIndex',
                data() {
                    return {
                        active: 0,
                        pagentname:"swe",
                        stitle: "daf1",
                        sdatetime: "323sd",
                        szvalue: false,
                        wjzh: "",
                        bzmc: "vad22323",
                        mima: "123456",
                        mima2: "123456",
                        czmima: "123423",
                        bzinfo: "",
                        game1_refund: 0.8,
                        game2_refund: 0,
                        game1_proportion: 100,
                        game2_proportion: 100,
                        game1_refund_max: 0.8,
                        game2_refund_max: 0,
                        game1_proportion_max: 80,
                        game2_proportion_max: 80,
                        handicap:"",
                        size: '',
                        nexttitle: "下一步",
                        tableData: [],
                        multipleSelection: [],
                        newdduser_id:0
                    };
                },
                mounted: function () {
                    this.pagentname = WSdata.agentself.name;
                    this.game1_refund = WSdata.agentself.game1_refund;
                    this.game2_refund = WSdata.agentself.game2_refund;
                    this.game1_proportion = WSdata.agentself.game1_proportion;
                    this.game2_proportion = WSdata.agentself.game2_proportion;

                    this.game1_refund_max =  WSdata.agentself.game1_refund;
                    this.game2_refund_max = WSdata.agentself.game2_refund;
                    this.game1_proportion_max = WSdata.agentself.game1_proportion;
                    this.game2_proportion_max = WSdata.agentself.game2_proportion;

                    console.log(WSdata.agentself);
                    this.getinfo();
                },
                methods: {
                    getinfo() {
                        //this.tableData
                        let that = this;
                        var url = "/api/bjl/gethandicaplist";
                        Fast.api.ajax({
                            url: url,
                            loading: 0
                        }, function (data, ret) {
                            console.log(data);
                            that.tableData = data;

                            return false;
                        }, function (data, ret) {
                            return false;
                        });
                    },
                    next() {
                        if (this.active == 0) {
                            if (this.wjzh.length < 1 || this.bzmc.length < 2 || this.mima.length < 2 || this.mima != this.mima2) {
                                this.$message({
                                    type: 'error',
                                    message: '账号密码输入错误!'
                                });
                                return;
                            }
                        } else if (this.active == 1) {
                            console.log("AAS", this.game1_proportion, WSdata.agentself.game1_proportion, this.game1_refund, WSdata.agentself.game1_refund);
                            if (this.game1_proportion > WSdata.agentself.game1_proportion) {
                                this.$message({
                                    type: 'error',
                                    message: '請輸入不大於本級代理佔成' + WSdata.agentself.game1_proportion + '%的佔成數!'
                                });
                                return;
                            }

                            if (this.game1_refund > WSdata.agentself.game1_refund ) {
                                this.$message({
                                    type: 'error',
                                    message: '請輸入不大於本級代理洗碼比' + WSdata.agentself.game1_refund + '%的洗碼比!'
                                });
                                return;
                            }
                        }

                        this.active++;
                        if (this.active == 4) {
                            this.nexttitle = "提交";
                        }

                        if (this.active == 5) {
                            console.log("3221");

                            var url = "/api/bjl/postagent";
                            let that = this;
                            Fast.api.ajax({
                                url: url,
                                data: {
                                    pid: WSdata.agentself.id,
                                    wjzh: that.wjzh,
                                    bzmc: that.bzmc,
                                    mima: that.mima,
                                    bzinfo: that.bzinfo,
                                    game1_proportion: that.game1_proportion,
                                    game2_proportion: that.game2_proportion,
                                    game1_refund: that.game1_refund,
                                    game2_refund: that.game2_refund,
                                    czmima: that.czmima,
                                    handicap: that.handicap
                                },
                            }, function (data, ret) {
                                console.log(data);
                                that.newdduser_id = data.id;
                                that.todo();
                                return true;
                            }, function () {
                                return true;
                            });
                        }
                        //console.log(this.multipleSelection);
                    },
                    todo() {
                        this.$confirm('创建成功，请选择继续分配额度或返回列表?', '提示', {
                            confirmButtonText: '返回列表',
                            cancelButtonText: '继续分配额度',
                            center: true,
                            type: 'warning'
                        }).then(() => {
                            this.$message({
                                type: 'success',
                                message: '返回列表成功!'
                            });

                            var index = parent.Layer.getFrameIndex(window.name);
                            parent.Layer.close(index);
                            window.parent.location.reload();

                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '继续分配额度'
                            });

                            let index = parent.Layer.getFrameIndex(window.name);

                            var url = 'dd/user/edfp/ids/' + this.newdduser_id;
                            var options = {
                                shadeClose: false,
                                shade: [0.3, '#393D49'],
                                area: ["80%", "80%"],
                                callback: function (data) {
                                    console.log(data);
                                    parent.Layer.close(index);
                                    window.parent.location.reload();
                                }
                            };
                            Fast.api.open(url, "继续分配额度", options);

                        });
                    },
                    back() {
                        this.active--;
                        if (this.active < 1) {
                            this.active = 0;
                        }
                        this.nexttitle = "下一步";
                    },
                    toggleSelection(rows) {
                        if (rows) {
                            rows.forEach(row => {
                                this.$refs.multipleTable.toggleRowSelection(row);
                            });
                        } else {
                            this.$refs.multipleTable.clearSelection();
                        }
                    },
                    handleSelectionChange(val) {
                        this.multipleSelection = val;
                        this.handicap = "";
                        for (let item of val) {
                            console.log(item);
                            this.handicap += item.id + ",";
                        }
                        if (this.handicap.length > 1) {
                            this.handicap = this.handicap.substr(0, this.handicap.length-1);
                        }
                        console.log("handicap=" + this.handicap);
                    },
                    handleChange(newVal) {
                        console.log('Switch value changed to:', newVal);
                        // 在这里，你可以根据 newVal（新的开关状态）执行一些逻辑
                        if (newVal) {
                            this.wjzh = this.generateComplexRandomAccount(10);
                        } else {
                            this.wjzh = "";
                        }
                    },
                    generateComplexRandomAccount(length) {
                        var result = '';
                        var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
                        var requiredTypes = {
                            uppercase: false,
                            lowercase: false,
                            digit: false
                        };
                        var charactersLength = characters.length;

                        while (Object.values(requiredTypes).includes(false) && result.length < length) {
                            var randomIndex = Math.floor(Math.random() * charactersLength);
                            var randomChar = characters.charAt(randomIndex);

                            if (
                                (randomChar >= 'A' && randomChar <= 'Z' && !requiredTypes.uppercase) ||
                                (randomChar >= 'a' && randomChar <= 'z' && !requiredTypes.lowercase) ||
                                (randomChar >= '0' && randomChar <= '9' && !requiredTypes.digit)
                            ) {
                                result += randomChar;
                                if (randomChar >= 'A' && randomChar <= 'Z') requiredTypes.uppercase = true;
                                if (randomChar >= 'a' && randomChar <= 'z') requiredTypes.lowercase = true;
                                if (randomChar >= '0' && randomChar <= '9') requiredTypes.digit = true;
                            }
                        }

                        // If the account is still too short, fill it with random characters
                        while (result.length < length) {
                            result += characters.charAt(Math.floor(Math.random() * charactersLength));
                        }

                        return result;
                    }
                }

            })

        },
        edit2: function () {
            new Vue({
                el: '#configIndex',
                data() {
                    return {
                        active: 0,
                        pagentname:"swe",
                        stitle: "daf1",
                        sdatetime: "323sd",
                        szvalue: false,
                        wjzh: "",
                        bzmc: "vad22323",
                        mima: "123456",
                        mima2: "123456",
                        czmima: "123423",
                        bzinfo: "",
                        game1_refund: 0.8,
                        game2_refund: 0,
                        game1_proportion: 80,
                        game2_proportion: 80,
                        game1_refund_max: 0.8,
                        game2_refund_max: 0,
                        game1_proportion_max: 80,
                        game2_proportion_max: 80,
                        handicap:"",
                        size: '',
                        nexttitle: "下一步",
                        tableData: [],
                        multipleSelection: [],
                        newdduser_id:0,
                        selectinit:0,
                    };
                },
                mounted: function () {
                    this.pagentname = WSdata.agentself.name;
                    console.log(WSdata.agentself);
                    this.wjzh = WSdata.agentedit.user.login_name;
                    this.bzmc  = WSdata.agentedit.user.nickname;
                    this.bzinfo  = WSdata.agentedit.user.remark;
                    this.czmima  = WSdata.agentedit.user.czmima;
                    this.mima  = WSdata.agentedit.user.mima;
                    this.mima2  = this.mima;
                    this.game1_refund =  WSdata.agentedit.game1_refund;
                    this.game2_refund = WSdata.agentedit.game2_refund;
                    this.game1_proportion = WSdata.agentedit.game1_proportion;
                    this.game2_proportion = WSdata.agentedit.game2_proportion;

                    this.game1_refund_max =  WSdata.agentedit.game1_refund;
                    this.game2_refund_max = WSdata.agentedit.game2_refund;
                    this.game1_proportion_max = WSdata.agentedit.game1_proportion;
                    this.game2_proportion_max = WSdata.agentedit.game2_proportion;

                    this.handicap = WSdata.agentedit.user.handicap;

                    this.getinfo();

                },
                methods: {
                    getinfo() {
                        //this.tableData
                        let that = this;
                        var url = "/api/bjl/gethandicaplist";
                        Fast.api.ajax({
                            url: url,
                            loading: 0
                        }, function (data, ret) {
                            //console.log(data);
                            that.tableData = data;
                            return false;
                        }, function (data, ret) {
                            return false;
                        });
                    },
                    next() {
                        if (this.active == 0) {
                            if (this.wjzh.length < 1 || this.bzmc.length < 2 || this.mima.length < 2 || this.mima != this.mima2) {
                                this.$message({
                                    type: 'error',
                                    message: '账号密码输入错误!'
                                });
                                return;
                            }
                        } else if (this.active == 1) {
                            if (this.game1_proportion > WSdata.agentself.game1_proportion) {
                                this.$message({
                                    type: 'error',
                                    message: '請輸入不大於本級代理佔成' + WSdata.agentself.game1_proportion + '%的佔成數!'
                                });
                                return;
                            }

                            if (this.game1_refund > WSdata.agentself.game1_refund ) {
                                this.$message({
                                    type: 'error',
                                    message: '請輸入不大於本級代理洗碼比' + WSdata.agentself.game1_refund + '%的洗碼比!'
                                });
                                return;
                            }
                        }

                        this.active++;
                        if (this.active == 1 && this.selectinit == 0) {
                            this.selecttog();
                            this.selectinit = 1;
                        }

                        if (this.active == 4) {
                            this.nexttitle = "提交";
                        }

                        if (this.active == 5) {
                            console.log("3221");

                            var url = "/api/bjl/postagent";
                            let that = this;
                            Fast.api.ajax({
                                url: url,
                                data: {
                                    pid: WSdata.agentself.id,
                                    id: WSdata.agentedit.id,
                                    wjzh: that.wjzh,
                                    bzmc: that.bzmc,
                                    mima: that.mima,
                                    bzinfo: that.bzinfo,
                                    game1_proportion: that.game1_proportion,
                                    game2_proportion: that.game2_proportion,
                                    game1_refund: that.game1_refund,
                                    game2_refund: that.game2_refund,
                                    czmima: that.czmima,
                                    handicap: that.handicap
                                },
                            }, function (data, ret) {
                                console.log(data);
                                that.newdduser_id = data.id;
                                that.todo();
                                return true;
                            }, function () {
                                return true;
                            });
                        }
                        //console.log(this.multipleSelection);
                    },
                    todo() {
                        this.$confirm('创建成功，请选择继续分配额度或返回列表?', '提示', {
                            confirmButtonText: '返回列表',
                            cancelButtonText: '继续分配额度',
                            center: true,
                            type: 'warning'
                        }).then(() => {
                            this.$message({
                                type: 'success',
                                message: '返回列表成功!'
                            });

                            var index = parent.Layer.getFrameIndex(window.name);
                            parent.Layer.close(index);

                        }).catch(() => {
                            this.$message({
                                type: 'info',
                                message: '继续分配额度'
                            });

                            let index = parent.Layer.getFrameIndex(window.name);

                            var url = 'dd/user/edfp/ids/' + this.newdduser_id;
                            var options = {
                                shadeClose: false,
                                shade: [0.3, '#393D49'],
                                area: ["80%", "80%"],
                                callback: function (data) {
                                    console.log(data);
                                    parent.Layer.close(index);
                                }
                            };
                            Fast.api.open(url, "继续分配额度", options);

                        });
                    },
                    back() {
                        this.active--;
                        if (this.active < 1) {
                            this.active = 0;
                        }
                        this.nexttitle = "下一步";
                    },
                    selecttog() {
                        let arr = this.handicap.split(",").map(Number);
                        var ss = [];
                        for (let i = 0; i < arr.length; i++) {
                            console.log(arr[i]); // 输出：1, 2, 3
                            var id = arr[i];

                            for (let j = 0; j < this.tableData.length; j++) {
                                if ( this.tableData[j].id == id) {
                                    ss[i] = this.tableData[j];
                                }
                            }
                        }
                        //this.toggleSelection([this.tableData[0], this.tableData[1]]);
                        this.toggleSelection(ss);
                    },
                    toggleSelection(rows) {
                        if (rows) {
                            rows.forEach(row => {
                                this.$refs.multipleTable.toggleRowSelection(row);
                            });
                        } else {
                            this.$refs.multipleTable.clearSelection();
                        }
                    },
                    handleSelectionChange(val) {
                        this.multipleSelection = val;
                        this.handicap = "";
                        for (let item of val) {
                            console.log(item);
                            this.handicap += item.id + ",";
                        }
                        if (this.handicap.length > 1) {
                            this.handicap = this.handicap.substr(0, this.handicap.length-1);
                        }
                        console.log("handicap=" + this.handicap);
                    },
                    handleChange(newVal) {
                        console.log('Switch value changed to:', newVal);
                        // 在这里，你可以根据 newVal（新的开关状态）执行一些逻辑
                        if (newVal) {
                            this.wjzh = this.generateComplexRandomAccount(10);
                        } else {
                            this.wjzh = "";
                        }
                    },
                    generateComplexRandomAccount(length) {
                        var result = '';
                        var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
                        var requiredTypes = {
                            uppercase: false,
                            lowercase: false,
                            digit: false
                        };
                        var charactersLength = characters.length;

                        while (Object.values(requiredTypes).includes(false) && result.length < length) {
                            var randomIndex = Math.floor(Math.random() * charactersLength);
                            var randomChar = characters.charAt(randomIndex);

                            if (
                                (randomChar >= 'A' && randomChar <= 'Z' && !requiredTypes.uppercase) ||
                                (randomChar >= 'a' && randomChar <= 'z' && !requiredTypes.lowercase) ||
                                (randomChar >= '0' && randomChar <= '9' && !requiredTypes.digit)
                            ) {
                                result += randomChar;
                                if (randomChar >= 'A' && randomChar <= 'Z') requiredTypes.uppercase = true;
                                if (randomChar >= 'a' && randomChar <= 'z') requiredTypes.lowercase = true;
                                if (randomChar >= '0' && randomChar <= '9') requiredTypes.digit = true;
                            }
                        }

                        // If the account is still too short, fill it with random characters
                        while (result.length < length) {
                            result += characters.charAt(Math.floor(Math.random() * charactersLength));
                        }

                        return result;
                    }
                }

            })

        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
